package strcy.cn.market.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import strcy.cn.market.pojo.ProductCategories;
import strcy.cn.market.service.ProductCategoryService;
import strcy.cn.market.utils.PageBean;
import strcy.cn.market.utils.Result;

import java.util.List;

@RestController
@RequestMapping("category")
public class ProductCategoryController {
    @Autowired
    private ProductCategoryService productCategoryService;

    //新增分类
    @PostMapping("/add")
    public Result addCategory(@RequestBody ProductCategories productCategories) {
        productCategoryService.add(productCategories);
        return Result.success();
    }
    //修改分类名
    @PutMapping("/update")
    public Result updateCategoryName(@RequestBody ProductCategories productCategories) {
        productCategoryService.update(productCategories);
        return Result.success();
    }
    //删除分类
    @DeleteMapping("{categoryId}")
    public Result deleteCategory(@PathVariable("categoryId") Integer id) {
        productCategoryService.deleteByID(id);
        return Result.success();
    }
    //查询分类列表
    @GetMapping("/list")
    public Result<List<ProductCategories>> getList(){
       List<ProductCategories> list = productCategoryService.list();
        return Result.success(list);
    }
    //分页查询
    @GetMapping("/pageList")
    public Result<PageBean<ProductCategories>> getPageList(Integer pageNum, Integer pageSize){
        PageBean<ProductCategories> list = productCategoryService.pageList(pageNum,pageSize);
        return Result.success(list);
    }

}
